//
//  UnsentViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/15.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "UnsentViewController.h"
#import "XLSlideSwitch.h"//滑动滚动第三方
#import "RecommendViewController.h"//推荐
#import "HappyViewController.h"//开心
#import "CalmnessViewController.h"//平静
#import "SadViewController.h"//伤心
#import "IndignationViewController.h"//愤怒
#import "ElseViewController.h"//其他
#import "Masonry.h"
#import "SmoothChartView.h"
#import "SmoothChartTwoView.h"
#import "BrokenChartView.h"
#import "TwoViewController.h"
@interface UnsentViewController ()<XLSlideSwitchDelegate , UIScrollViewDelegate>
{
    SmoothChartView *_smoothView;
    SmoothChartTwoView *_smoothTwoView;
    BrokenChartView *_brokenView;
    UIScrollView *sc; //滚动式图
    UIPageControl *pageC; //分页控制符
    NSArray *imgArr; //图片数组
    NSTimer *timer; //时间定时器
    int k; //计数
    UIView *backgroundView;
    UIView *backgroundView1;
    NSArray *AbsorbedArr;
    NSArray *EmotionArr;
}
@property (nonatomic , strong)XLSlideSwitch *ScrollView;///滚动视图

@end

@implementation UnsentViewController
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    AbsorbedArr = @[@"早读" , @"课外活动" , @"早读" , @"课外活动" , @"早读" , @"课外活动" , @"课外课"];
    EmotionArr  = @[@"早读" , @"课外活动" , @"早读" , @"课外活动" , @"早读" , @"课外活动" , @"课外课"];
    //(推荐.开心.平静.伤心.愤怒.其他)---> Controller滚动视图
    [self scview];
    //曲线的滚动视图  滚动View; and 滚动的豆豆;
    [self cvll];
    // 平滑曲线带阴影
    [self makeSmoothChartView];
    [self makeSmoothChartTwoView];
    // Do any additional setup after loading the view from its nib.
}

- (void)scview{
    NSArray *TitlesArr = @[@"推荐" , @"开心" , @"平静" , @"伤心" , @"愤怒" , @"其他"];
    NSArray *ControllersArr = @[@"RecommendViewController" , @"HappyViewController" , @"CalmnessViewController" , @"SadViewController" , @"IndignationViewController" , @"ElseViewController"];
    NSMutableArray *ViewControllers = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < TitlesArr.count; i ++) {
        //字符串创建控制器
        UIViewController *VC = [[NSClassFromString(ControllersArr[i])alloc] init];
        [ViewControllers addObject:VC];
    }
    //滚动视图
    _ScrollView = [[XLSlideSwitch alloc] initWithFrame:CGRectMake(0, 450, self.view.bounds.size.width, self.view.bounds.size.height - 450 - 48) Titles:TitlesArr viewControllers:ViewControllers];
    _ScrollView.delegate = self;
    //rgba(102/255.0, 102, 102, 1)
    _ScrollView.itemNormalColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
    //rgba(72/255.0, 169/255.0, 54/255.0, 1)
    _ScrollView.itemSelectedColor = [UIColor colorWithRed:72/255.0 green:169/255.0 blue:54/255.0 alpha:1];
    _ScrollView.customTitleSpacing = 30;
    _ScrollView.hideShadow=YES;
    [_ScrollView showInViewController:self];
    _ScrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [_ScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(400);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(-0);
        make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).inset(0);
    }];
}
- (void)cvll{
    sc = [[UIScrollView alloc] initWithFrame:self.view.frame];
    //设置滚动式图的代理
    sc.delegate = self;
    //滚动范围
    sc.contentSize = CGSizeMake(self.view.frame.size.width*2, 0);
    //分页
    sc.pagingEnabled = YES;
    //弹簧
    sc.bounces = NO;
    //禁用水平滚动条
    sc.showsHorizontalScrollIndicator = NO;
    //view1--->专注曲线
    backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 270)];
    backgroundView.backgroundColor = [UIColor whiteColor];
    //view2--->情绪曲线
    backgroundView1 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, 270)];
    backgroundView1.backgroundColor = [UIColor whiteColor];
    
    //把两个视图添加到滚动试图上
    [sc addSubview:backgroundView];
    [sc addSubview:backgroundView1];
    //把滚动试图添加到self.view 并且进行适配
    [self.view addSubview:sc];
    [sc mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(164);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(-0);
        make.size.height.mas_equalTo(270);
    }];
    //豆豆
    pageC = [[UIPageControl alloc] initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 200, 200, 40)];
    //豆豆的数量
    pageC.numberOfPages = 2;
    //豆豆颜色
    pageC.pageIndicatorTintColor = [UIColor blackColor];
    pageC.currentPageIndicatorTintColor = [UIColor orangeColor];
    //默认选中
    pageC.currentPage = 0;
    //将豆豆网滚动视图里加
    [self.view addSubview:pageC];
    [pageC mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(380);
        make.left.mas_equalTo((self.view.frame.size.width-200)/2);
        make.right.mas_equalTo(-(self.view.frame.size.width-200)/2);
        make.size.height.mas_equalTo(40);
    }];
}
//视图已经滚动的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    pageC.currentPage = sc.contentOffset.x/self.view.frame.size.width;
    NSLog(@"%lf",sc.contentOffset.x);
}
#pragma mark - 作图表
-(void)makeSmoothChartView{
    
//    [self.view addSubview:backgroundView];
//    backgroundView.translatesAutoresizingMaskIntoConstraints = NO;
    
    //标题
    UILabel *TitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, self.view.bounds.size.width, 20)];
    TitleLabel.text = @"专注曲线";
    TitleLabel.textAlignment = NSTextAlignmentCenter;
    TitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    [backgroundView addSubview: TitleLabel];
    //图表放大
    UIButton *EnlargeBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 0, 100, 40)];
    [EnlargeBtn setBackgroundColor:[UIColor clearColor]];
    [EnlargeBtn addTarget:self action:@selector(EnlargeBtnMore) forControlEvents:UIControlEventTouchUpInside];
    UILabel *EnlargeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    EnlargeLabel.text = @"图表放大";
    //rgba(74/255.0, 137/255.0, 54/255.0, 1)
    EnlargeLabel.textColor = [UIColor colorWithRed:74/255.0 green:137/255.0 blue:54/255.0 alpha:1];
    EnlargeLabel.font = [UIFont systemFontOfSize:20];
    EnlargeLabel.textAlignment = NSTextAlignmentRight;//居右
    UIImageView *EnlargeImage = [[UIImageView alloc] initWithFrame:CGRectMake(-10, 5, 30, 30)];
    EnlargeImage.image = [UIImage imageNamed:@"放大"];
    [EnlargeBtn addSubview:EnlargeImage];
    [EnlargeBtn addSubview:EnlargeLabel];
    [backgroundView addSubview:EnlargeBtn];
    
    //./////////////////
    for (int i = 0; i < 7; i ++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60*i, 240, 50, 20)];
        //rgba(226/255.0, 242/255.0, 223/255.0, 1)
        label.backgroundColor = [UIColor colorWithRed:226/255.0 green:242/255.0 blue:223/255.0 alpha:1];
        label.text = AbsorbedArr[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:10];
        [backgroundView addSubview:label];
    }
    //平滑曲线图表
    _smoothView = [[SmoothChartView alloc] initWithFrame:CGRectMake(0, 40, (self.view.bounds.size.width-30),392/2)];
//    _smoothView.layer.cornerRadius = 10;
//    _smoothView.layer.masksToBounds = YES;
    _smoothView.backgroundColor = [UIColor whiteColor];
    //X轴刻度
    _smoothView.arrX = @[@"8:00",@"10:00",@"12:00" , @"14:00" , @"16:00" , @"18:00"];
    // Y轴刻度
    _smoothView.arrY = @[@"0",@"50",@"100"];
    [_smoothView refreshChartAnmition];
    NSArray *pathX = @[@"1",@"2.5",@"4",@"5.5",@"7",@"8.5" , @"10" , @"11.5" ,@"13"];
    NSArray *pathY = @[@"0",@"100",@"40",@"50",@"40",@"70",@"30" , @"60" , @"0"];
    [_smoothView drawSmoothViewWithArrayX:pathX andArrayY:pathY andScaleX:12.0];
    [backgroundView addSubview:_smoothView];
}
#pragma mark - 情绪曲线--->作图表
- (void)makeSmoothChartTwoView{
    //标题
    UILabel *TitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, self.view.bounds.size.width, 20)];
    TitleLabel.text = @"情绪曲线";
    TitleLabel.textAlignment = NSTextAlignmentCenter;
    TitleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    [backgroundView1 addSubview: TitleLabel];
    //图表放大
    UIButton *EnlargeBtn = [[UIButton alloc] initWithFrame:CGRectMake(280, 0, 100, 40)];
    [EnlargeBtn setBackgroundColor:[UIColor clearColor]];
    [EnlargeBtn addTarget:self action:@selector(EnlargeBtnMore) forControlEvents:UIControlEventTouchUpInside];
    UILabel *EnlargeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    EnlargeLabel.text = @"图表放大";
    //rgba(74/255.0, 137/255.0, 54/255.0, 1)
    EnlargeLabel.textColor = [UIColor colorWithRed:74/255.0 green:137/255.0 blue:54/255.0 alpha:1];
    EnlargeLabel.font = [UIFont systemFontOfSize:20];
    EnlargeLabel.textAlignment = NSTextAlignmentRight;//居右
    UIImageView *EnlargeImage = [[UIImageView alloc] initWithFrame:CGRectMake(-10, 5, 30, 30)];
    EnlargeImage.image = [UIImage imageNamed:@"放大"];
    [EnlargeBtn addSubview:EnlargeImage];
    [EnlargeBtn addSubview:EnlargeLabel];
    [backgroundView1 addSubview:EnlargeBtn];
    ///////
    for (int i = 0; i < 7; i ++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(60*i, 240, 50, 20)];
        //rgba(226/255.0, 242/255.0, 223/255.0, 1)
        //rgba(254, 243, 211, 1)
        label.backgroundColor = [UIColor colorWithRed:254/255.0 green:243/255.0 blue:211/255.0 alpha:1];
        label.text = AbsorbedArr[i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:10];
        [backgroundView1 addSubview:label];
    }
    
    //平滑曲线图表
    _smoothTwoView = [[SmoothChartTwoView alloc] initWithFrame:CGRectMake(20, 40, (self.view.bounds.size.width-30),392/2)];
    //    _smoothView.layer.cornerRadius = 10;
    //    _smoothView.layer.masksToBounds = YES;
    _smoothView.backgroundColor = [UIColor whiteColor];
    //X轴刻度
    _smoothTwoView.arrX = @[@"8:00",@"10:00",@"12:00" , @"14:00" , @"16:00" , @"18:00"];
    // Y轴刻度
    _smoothTwoView.arrY = @[@"0",@"50",@"100"];
    [_smoothTwoView refreshChartAnmition];
    NSArray *pathX = @[@"1",@"2.5",@"4",@"5.5",@"7",@"8.5" , @"10" , @"11.5" ,@"13"];
    NSArray *pathY = @[@"0",@"100",@"40",@"50",@"40",@"70",@"30" , @"60" , @"0"];
    [_smoothTwoView drawSmoothViewWithArrayX:pathX andArrayY:pathY andScaleX:12.0];
    [backgroundView1 addSubview:_smoothTwoView];
}
- (void)EnlargeBtnMore{
    NSLog(@"放大");
    TwoViewController *two = [TwoViewController new];
    two.modalPresentationStyle = UIModalPresentationOverFullScreen;
    two.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    //    two.modalPresentationStyle = UIModalPresentationOverFullScreen;
    [self presentViewController:two animated:YES completion:nil];
}
- (IBAction)BackBtn:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
-(BOOL)shouldAutorotate{
    return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}
@end
